#region imported Namespaces
using System;
using System.Data;

using BO = PHSRAG.Insight21.BusinessObjects;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
#endregion

namespace PHSRAG.Insight21.Personnel
{
	#region Class Labor Distribution
	/// <summary>
	/// The LaborDistribution class is the facade over the distribution details for a single employee
	/// </summary>
	public class LaborDistribution : BO.BusinessObject
	{
		#region Constants
		private const string LaborDistributionKey			= "LaborDistribution_FF94AAB6-3BEE-4C9A-927C-719F7B693C77";
		//Constants to hold the column names
		private const string EarningsCodeColumnName			= "EarningsCode";
		private const string EmployeeNameColumnName			= "EmployeeName";
		private const string FundNumberColumnName			= "FundNumber";
		private const string JobCodeColumnName				= "JobCode";
		private const string PayDateColumnName				= "PayDate";
		private const string PayAmountColumnName			= "PayAmount";
		private const string RetroAdjustmentDateColumnName	= "RetroPayAdjustmentDate";

        private const string TransactionIdColumnName        = "TransactionId";
        private const string TransactionDateColumnName      = "TransactionDate";
        private const string JournalIdColumnName            = "JournalId";
        private const string JournalLineColumnName          = "JournalLine";
        private const string BusinessUnitColumnName         = "BusinessUnit";
        private const string AccountIdColumnName            = "AccountId";
        private const string AccountNumberColumnName        = "AccountNumber";
        private const string AccountNameColumnName          = "AccountName";
        private const string AmountColumnName               = "Amount";
        private const string DatePostedColumnName           = "DatePosted";
        private const string EntryDescriptionColumnName     = "EntryDescription";
        #endregion
		
		#region Instance variables
		private DataRow distributionRow;
		#endregion

		#region Public properties
		/// <summary>
		/// Get the Earnings Code Description for the salary transaction
		/// Return an empty string if there is no earnings code for the salary transaction
		/// </summary>
		public string EarningsCode
		{
			get
			{
				object earningsCode = distributionRow[EarningsCodeColumnName];
				return (earningsCode == DBNull.Value)?string.Empty:earningsCode.ToString();
			}
		}

		/// <summary>
		/// Get the name of the employee
		/// Return an empty string if there is no name for the employee
		/// </summary>
		public string EmployeeName
		{
			get
			{
				object employeeName = distributionRow[EmployeeNameColumnName];
				return (employeeName == DBNull.Value)?string.Empty:employeeName.ToString();
			}
		}
		/// <summary>
		/// Get the fund on which the employee was paid
		/// Return an empty string if there is no fund number associated
		/// </summary>
		public string FundNumber
		{
			get
			{
				object fundNumber = distributionRow[FundNumberColumnName];
				return (fundNumber == DBNull.Value)?string.Empty:fundNumber.ToString();
			}
		}
		/// <summary>
		/// Get the Job Code for the employee's salary transaction
		/// Return an empty string if there is no job code for the employee's salary transaction
		/// </summary>
		public string JobCode
		{
			get
			{
				object jobCode = distributionRow[JobCodeColumnName];
				return (jobCode == DBNull.Value)?string.Empty:jobCode.ToString();
			}
		}
		/// <summary>
		/// Get the date on which the employee was paid
		/// Return an empty string if there is no pay date
		/// </summary>
		public string PayDate
		{
			get
			{
				object payDate = distributionRow[PayDateColumnName];
				return (payDate == DBNull.Value)?
					string.Empty:((DateTime)payDate).ToString("MM/dd/yyyy");
			}
		}
		/// <summary>
		/// Get the amount of money the employee was paid for each week in a month
		/// Return an empty string if there is no pay amount
		/// </summary>
		public string PayAmount
		{
			get
			{
				object payAmount = distributionRow[PayAmountColumnName];
				return (payAmount == DBNull.Value)?string.Empty:payAmount.ToString();
			}
		}
		/// <summary>
		/// Get the retro adjustment date for the employee's salary transaction
		/// Return an empty string if there is no retro adjustment date
		/// </summary>
		public string RetroAdjustmentDate
		{
			get
			{
				object retroAdjustmentDate = distributionRow[RetroAdjustmentDateColumnName];
				return (retroAdjustmentDate == DBNull.Value)?
					string.Empty:((DateTime)retroAdjustmentDate).ToString("MM/dd/yyyy");
			}
		}

        /// <summary>
        /// set of properties for General Ledger dataRow. Added 10/06/2008 TracIt # 8822
        /// </summary>
        public int TransactionId
        {
            get
            {
                object transactionId = distributionRow[TransactionIdColumnName];
                return (transactionId == DBNull.Value) ? 0 : Convert.ToInt32(transactionId);
            }
        }

        /// transaction date
        public string TransactionDate
        {
            get
            {
                object transactionDate = distributionRow[TransactionDateColumnName];
                return (transactionDate == DBNull.Value) ? string.Empty : transactionDate.ToString();
            }
        }

        /// journal Id
        public string JournalId
        {
            get
            {
                object journalId = distributionRow[JournalIdColumnName];
                return (journalId == DBNull.Value) ? string.Empty : journalId.ToString();
            }
        }

        /// journal line
        public int JournalLine
        {
            get
            {
                object journalLine = distributionRow[JournalLineColumnName];
                return (journalLine == DBNull.Value) ? 0 : Convert.ToInt32(journalLine);
            }
        }

        /// business unit
        public string BusinessUnit
        {
            get
            {
                object businessUnit = distributionRow[BusinessUnitColumnName];
                return (businessUnit == DBNull.Value) ? string.Empty : businessUnit.ToString();
            }
        }

        /// account id
        public string AccountId
        {
            get
            {
                object accountId = distributionRow[AccountIdColumnName];
                return (accountId == DBNull.Value) ? string.Empty : accountId.ToString();
            }
        }
        /// account number
        public string AccountNumber
        {
            get
            {
                object accountNumber = distributionRow[AccountNumberColumnName];
                return (accountNumber == DBNull.Value) ? string.Empty : accountNumber.ToString();
            }
        }
        /// account Name
        public string AccountName
        {
            get
            {
                object accountName = distributionRow[AccountNameColumnName];
                return (accountName == DBNull.Value) ? string.Empty : accountName.ToString();
            }
        }

        /// amount
        public double Amount
        {
            get
            {
                object amount = distributionRow[AmountColumnName];
                return (amount == DBNull.Value) ? 0 : Convert.ToDouble(amount);
            }
        }

        /// date posted
        public string DatePosted
        {
            get
            {
                object datePosted = distributionRow[DatePostedColumnName];
                return (datePosted == DBNull.Value) ? string.Empty : datePosted.ToString();
            }
        }

        /// entry description
        public string EntryDescription
        {
            get
            {
                object entryDescription = distributionRow[EntryDescriptionColumnName];
                return (entryDescription == DBNull.Value) ? string.Empty : entryDescription.ToString();
            }
        }

		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the base class with the specified cache policy and assign the DataRow to the instance variable
		/// </summary>
		/// <param name="cachePolicy">Prevalent cache policy</param>
		/// <param name="dataRow">DataRow containing Labor distribution data</param>
		public LaborDistribution(ICachePolicy cachePolicy,DataRow dataRow):base(cachePolicy)
		{
			distributionRow = dataRow;
		}
		#endregion

		#region BusinessObject Methods
		/// <summary>
		/// Cache the LaborDistribution instance using the prevalent cache policy
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(LaborDistributionKey,this);
		}
		/// <summary>
		/// Remove the LaborDistribution instance from the cache using the prevalent cache policy
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(LaborDistributionKey);
		}
		/// <summary>
		/// This method is not used and only exists to satisfy interface requirements.
		/// </summary>
		public override void Load(string connectionString, params object[] args)
		{			
			throw new Exception("Labout distribution cannot be directly loaded.");
		}
		#endregion
	}
	#endregion
}